<template>
  <el-container class="home_container">
    <!-- 头部 -->
    <el-header>
      <div class="home_header_left">
        <img src="../assets/caihua.png" alt />
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主题曲 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="togg-btn" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单区域 -->
        <el-menu
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          width="200px"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
        >
          <el-submenu :index="index + ''" v-for="(item,index) in navList" :key="index">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.OnNavName}}</span>
            </template>
            <el-menu-item-group v-for="(sanItem,sanIndex) in item.erji" :key="sanIndex">
              <el-menu-item :index="'/' + sanItem.url">{{sanItem.TwoNavName}}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
          <!-- 路由占位符 -->
          <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      isCollapse: false,
      navList: [
        {
          OnNavName: "用户管理",
          erji: [
            {
              TwoNavName: "管理列表",
              url:'Users'
            },
            {
              TwoNavName: "管理列表一",
              url:'Users1'
            },
            {
              TwoNavName: "管理列表二",
              url:'Users2'
            },
          ],
        },
        {
          OnNavName: "权限管理",
          erji: [
            {
              TwoNavName: "商家权限",
              url:'Users3'
            },
            {
              TwoNavName: "用户权限",
              url:'Users4'
            },
            {
              TwoNavName: "管理权限",
              url:'Users5'
            },
          ],
        },
        {
          OnNavName: "商品管理",
          erji: [
            {
              TwoNavName: "上架管理",
              url:'Users6'
            },
            {
              TwoNavName: "下架管理",
              url:'Users7'
            },
          ],
        },
      ],
    };
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("login");
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    // 点击按钮 切换菜单的折叠与展开
    toggleCollapse() {
        this.isCollapse = !this.isCollapse
    },
  },
};
</script>
<style scoped>
.home_container {
  height: 100%;
}
.home_header_left {
  display: flex;
  align-items: center;
}
.home_header_left img {
  widows: 50px;
  height: 50px;
  border-radius: 20rpx;
  margin-right: 20px;
}
.home_header_left span {
  color: #fff;
  font-size: 20px;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}
.el-aside .el-menu {
  border-right: 0;
  height: 100%;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.togg-btn {
  background: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>